06. Practice Solution #1

Practice Solution #1: Compute the Most Popular Start Hour

import pandas as pd

filename = 'chicago.csv'

# load data file into a dataframe
df = pd.read_csv(filename)

# convert the Start Time column to datetime
df['Start Time'] = pd.to_datetime(df['Start Time'])

# extract hour from the Start Time column to create an hour column
df['hour'] = df['Start Time'].dt.hour

# find the most popular hour
popular_hour = df['hour'].mode()[0]

print('Most Popular Start Hour:', popular_hour)

Outputs:

Most Popular Start Hour: 17